package com.dux.commons.scripts.java.impl.javacompiler;

import java.util.Locale;

import javax.tools.Diagnostic;
import javax.tools.DiagnosticListener;
import javax.tools.JavaFileObject;

import org.apache.log4j.Logger;

/**
 * 编译器错误监听类
 * @author 杜祥
 * @create 2013-6-17
 */
public class ErrorListener implements DiagnosticListener<JavaFileObject>
{
	
	private static final Logger log = Logger.getLogger(ErrorListener.class);

	@Override
	public void report(Diagnostic<? extends JavaFileObject> diagnostic) 
	{
		StringBuffer buffer = new StringBuffer();
		buffer.append("java编译器 ").append(diagnostic.getKind()).append(": ").append(
			diagnostic.getMessage(Locale.CHINESE)).append("\n").append("资源: ").append(
			diagnostic.getSource().getName()).append("\n").append("行: ").append(diagnostic.getLineNumber()).append(
			"\n").append("列: ").append(diagnostic.getColumnNumber());
		log.error(buffer.toString());
	}

}
